#pragma once
#include <iostream>
#include <string>
#include "protocol.hpp"
using namespace std;


enum {
    success = 0,
    divzero,
    modezero,
    unknow
};




// 计算
shared_ptr<Response> Cal(shared_ptr<Request> req) {
    shared_ptr<Response> resp = shared_ptr<Response>(new Response());
    resp->SetCode(success);
    switch (req->GetOp()) {
        case '+' :
            resp->SetResult(req->GetX() + req->GetY());
            break;
        case '-' :
            resp->SetResult(req->GetX() - req->GetY());
            break;
        case '*' :
            resp->SetResult(req->GetX() * req->GetY());
            break;
        case '/' :
            {
                if (req->GetY() == 0) {
                    resp->SetResult(-1);   
                    resp->SetCode(divzero);
                } else {
                    resp->SetResult(req->GetX() / req->GetY());
                }
                break;
            }
        case '%' :
            {
                if (req->GetY() == 0) {
                    resp->SetResult(-1);   
                    resp->SetCode(modezero);
                } else {
                    resp->SetResult(req->GetX() % req->GetY());
                }
                break;
            }
        default :
            {
                resp->SetResult(-1);
                resp->SetCode(unknow);
                break;
            }
    }
    return resp;
}

